<#assign module="zhuanche"/>
<@override name="header">
</@override>
<@override name="body">

<div class="tabbable tabs-left">
	<div class="row">
		<div class="col-xs-12">
			<div class="orders-navt">
				<ul class="orders-nav">
	                <@shiro.hasPermission name='zhuanCar'>
	                	<li><a  href="${ctx}/zhuanche/cars" >车辆</a></li>
	                </@shiro.hasPermission>
	                <@shiro.hasPermission name='zhuanCar'>
	                	<li class="orders-click" style="width:auto;"><a data-toggle="tab" href="#" class="orders-click-a" > &emsp;${carTypeName}&emsp;</a></li>
	                </@shiro.hasPermission>
	                	<li><a  style="font-size:18px;" href="${ctx}/zhuanche/carTypes">返回</a></li>
	            </ul>
	    	</div>
	    	<div class="orders-navh">
		       <button class="pull-right btn btn-primary startService"><i class="icon-plus"></i>&nbsp;开通车型</button>
			</div>
		</div>
	</div>
</div>
<div class="tab-content">
	<div class="container-fluid ">
	 <@shiro.isMainCompany>
  		<div class="row query-pad">
  			<div class="col-xs-11" style="padding: 0px;">
      			<div class="col-xs-4 input-query">
      				<span>公司名称:</span>
      				<input type="text" class="form-control form-contb" id="companyName" name="companyName" placeholder="请输入公司名字"/>
        		</div>
    		</div>
    		<div class="col-xs-1"style="padding: 0px;">
    			<div class="input-query-bttom">
        			<button id="searchButton" type="button">查询</button>
        		</div>
    		</div>
  		</div>
  	 </@shiro.isMainCompany>	
  		<br/>
  	</div>
</div>
<!--列表-->
<div class="tabta-content">  	
	<table class="table table-condensed table-striped">
		<tbody id="carType_tbody">
			<tr>
				<tr>
					<th class="col-xs-2">公司名称</th>
					<th class="col-xs-1">立即用车收费</th>
					<th class="col-xs-1">日租收费</th>
					<th class="col-xs-1">半日租收费</th>
					<th class="col-xs-1">接机收费</th>
					<th class="col-xs-1">送机收费</th>
					<th class="col-xs-1">接站收费</th>
					<th class="col-xs-1">送站收费</th>
					<th class="col-xs-2">操作</th>
				</tr>
			</tr>
		</tbody>
	</table>
	
	<ul class="pagination pull-left pagination-sm pageshow" style="display:none;">
		<li><a></a></li>
	</ul>
	<ul class="pagination pull-left pagination-sm pagedata" style="display:none;">
    </ul>
</div>
<!--开通公司-->
<div class="form-horizontal">
	<div class="modal fade" id="dialog_carTypeCompany_create">
	   <div class="modal-dialog">
	     <div class="modal-content">
	    	<div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
	        	<h4 class="modal-title">开通公司</h4>
	        </div>
		    <div class="modal-body">
	      	<form action=""  method="post">
		         <div class="form-group">
                    <label class="col-sm-3 control-label">汽车类型:</label>
                    <div class="col-sm-8">
                    	<label class="col-sm-4 control-label" >${carTypeName}</label>
                    </div>
				 </div>
	      		 <div class="form-group">
	                <label class="col-sm-3 control-label">所属公司:</label>
	                <div class="col-sm-8">
		                <select class="form-control" id="companyId_company" >
							<#if companys??>
								<#list companys as company>
									<option value="${company.id}" <#if companyId?? && companyId==company.id>selected="selected"</#if>>${company.abbreviation?if_exists}</option>
								</#list>
							</#if>
						</select>
	                </div>
				 </div>
		         <div class="form-group">
	                <label class="col-sm-3 control-label">立即用车收费:</label>
	                <div class="col-sm-8">
		                <select class="form-control" id="tangzuAreaId_company" >
							<#if arealist??>
								<#list arealist as area>
								<option value="${area.id}" >${area.name?if_exists}</option>
								</#list>
							</#if>
						</select>
	                </div>
				 </div>
		         <div class="form-group">
	                <label class="col-sm-3 control-label">日租收费:</label>
	                <div class="col-sm-8">
		                <select class="form-control" id="rizuAreaId_company" >
							<#if arealist??>
								<#list arealist as area>
								<option value="${area.id}" >${area.name?if_exists}</option>
								</#list>
							</#if>
						</select>
	                </div>
				 </div>
		         <div class="form-group">
	                <label class="col-sm-3 control-label">半日收费:</label>
	                <div class="col-sm-8">
		                <select class="form-control" id="banrizuAreaId_company" >
							<#if arealist??>
								<#list arealist as area>
								<option value="${area.id}" >${area.name?if_exists}</option>
								</#list>
							</#if>
						</select>
	                </div>
				 </div>
		         <div class="form-group">
	                <label class="col-sm-3 control-label">接机收费:</label>
	                <div class="col-sm-8">
		                <select class="form-control" id="jiejiAreaId_company" >
							<#if arealist??>
								<#list arealist as area>
								<option value="${area.id}" >${area.name?if_exists}</option>
								</#list>
							</#if>
						</select>
	                </div>
				 </div>
		         <div class="form-group">
	                <label class="col-sm-3 control-label">送机收费:</label>
	                <div class="col-sm-8">
		                <select class="form-control" id="songjiAreaId_company" >
							<#if arealist??>
								<#list arealist as area>
								<option value="${area.id}" >${area.name?if_exists}</option>
								</#list>
							</#if>
						</select>
	                </div>
				 </div>
		         <div class="form-group">
	                <label class="col-sm-3 control-label">接站收费:</label>
	                <div class="col-sm-8">
		                <select class="form-control" id="jiezhanAreaId_company" >
							<#if arealist??>
								<#list arealist as area>
								<option value="${area.id}" >${area.name?if_exists}</option>
								</#list>
							</#if>
						</select>
	                </div>
				 </div>
		         <div class="form-group">
	                <label class="col-sm-3 control-label">送站收费:</label>
	                <div class="col-sm-8">
		                <select class="form-control" id="songzhanAreaId_company" >
							<#if arealist??>
								<#list arealist as area>
								<option value="${area.id}" >${area.name?if_exists}</option>
								</#list>
							</#if>
						</select>
	                </div>
				 </div>
				 <div class="form-group">
             	 	<div class="col-sm-6">
            	 	</div>
            	 	<div class="col-sm-3">
				      <input  type="button" class="btn btn-primary" id="startService_company" value="开通">
				      <button type="button" class="btn btn-default" id="close_modal_company">取消</button>
	        	  	</div>
	           </div>  
		  	</form>
	     	</div>
	     </div>
	  </div>
	</div>
</div>
<!--修改公司车型收费-->
<div class="form-horizontal">
	<div class="modal fade" id="dialog_carTypeCompany_update">
	   <div class="modal-dialog">
	     <div class="modal-content">
	    	<div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
	        	<h4 class="modal-title">修改公司收费</h4>
	        </div>
		    <div class="modal-body">
	      	<form action=""  method="post">
	      		<input type="hidden" id="companyId_update"/>
		         <div class="form-group">
                    <label class="col-sm-3 control-label">汽车类型:</label>
                    <div class="col-sm-8">
                    	<label class="control-label" >${carTypeName}</label>
                    </div>
				 </div>
	      		 <div class="form-group">
	                <label class="col-sm-3 control-label">所属公司:</label>
	                <div class="col-sm-8">
	                	<label id="companyName_update" class="control-label" ></label>
	                </div>
				 </div>
		         <div class="form-group">
	                <label class="col-sm-3 control-label">立即用车收费:</label>
	                <div class="col-sm-8">
		                <select class="form-control" id="tangzuAreaId_company_update" >
							<#if arealist??>
								<#list arealist as area>
								<option value="${area.id}" >${area.name?if_exists}</option>
								</#list>
							</#if>
						</select>
	                </div>
				 </div>
		         <div class="form-group">
	                <label class="col-sm-3 control-label">日租收费:</label>
	                <div class="col-sm-8">
		                <select class="form-control" id="rizuAreaId_company_update" >
							<#if arealist??>
								<#list arealist as area>
								<option value="${area.id}" >${area.name?if_exists}</option>
								</#list>
							</#if>
						</select>
	                </div>
				 </div>
		         <div class="form-group">
	                <label class="col-sm-3 control-label">半日收费:</label>
	                <div class="col-sm-8">
		                <select class="form-control" id="banrizuAreaId_company_update" >
							<#if arealist??>
								<#list arealist as area>
								<option value="${area.id}" >${area.name?if_exists}</option>
								</#list>
							</#if>
						</select>
	                </div>
				 </div>
		         <div class="form-group">
	                <label class="col-sm-3 control-label">接机收费:</label>
	                <div class="col-sm-8">
		                <select class="form-control" id="jiejiAreaId_company_update" >
							<#if arealist??>
								<#list arealist as area>
								<option value="${area.id}" >${area.name?if_exists}</option>
								</#list>
							</#if>
						</select>
	                </div>
				 </div>
		         <div class="form-group">
	                <label class="col-sm-3 control-label">送机收费:</label>
	                <div class="col-sm-8">
		                <select class="form-control" id="songjiAreaId_company_update" >
							<#if arealist??>
								<#list arealist as area>
								<option value="${area.id}" >${area.name?if_exists}</option>
								</#list>
							</#if>
						</select>
	                </div>
				 </div>
		         <div class="form-group">
	                <label class="col-sm-3 control-label">接站收费:</label>
	                <div class="col-sm-8">
		                <select class="form-control" id="jiezhanAreaId_company_update" >
							<#if arealist??>
								<#list arealist as area>
								<option value="${area.id}" >${area.name?if_exists}</option>
								</#list>
							</#if>
						</select>
	                </div>
				 </div>
		         <div class="form-group">
	                <label class="col-sm-3 control-label">送站收费:</label>
	                <div class="col-sm-8">
		                <select class="form-control" id="songzhanAreaId_company_update" >
							<#if arealist??>
								<#list arealist as area>
								<option value="${area.id}" >${area.name?if_exists}</option>
								</#list>
							</#if>
						</select>
	                </div>
				 </div>
				 <div class="form-group">
             	 	<div class="col-sm-6">
            	 	</div>
            	 	<div class="col-sm-3">
				      <input  type="button" class="btn btn-primary" id="startService_company_update" value="修改">
				      <button type="button" class="btn btn-default" id="close_modal_company_update">取消</button>
	        	  	</div>
	           </div>  
		  	</form>
	     	</div>
	     </div>
	  </div>
	</div>
</div>

</@override>
<@override name="footer">
<script type="text/javascript">
  var isMainCompany=false;
  var carTypeId=${carTypeId};
 <@shiro.isMainCompany>
      isMainCompany=true;
 </@shiro.isMainCompany>
</script>
<script src="${ctx}/assets/js/ajaxfileupload.js"></script>
<script src="${ctx}/assets/js/jquery.paging.min.js"></script>
<script src="${ctx}/assets/js/zhuanche/carTypeCompany.js"></script>
<script type="text/javascript">
 	//删除
    var thisButton;
    function deleteCarTypeCompany() {
		if(thisButton.attr("data-value").trim()==null  || thisButton.attr("data-value").trim()==""){
			$.scojs_message("公司车型不存在！", $.scojs_message.TYPE_ERROR);
			return false;
		}
	    $.get('${ctx}/zhuanche/deleteCarTypeCompany',{'carTypeCompanyId':thisButton.attr("data-value")},function(data){
            if(data.code==0){
            	thisButton.parent().parent().remove();
                $.scojs_message('公司车型取消成功', $.scojs_message.TYPE_OK);
                 setTimeout(function(){
						window.location.reload(true);
					}, 800);
            } else {
                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
            }
	    },'json');
	}
	$(document).ready(function(){
	    $(document).on("click",".deleteTypeCompany",function(){
	          thisButton = $(this);
	          var confirm = $.scojs_confirm({
	            content: "你真的要取消开通该车型吗？专车车型不会被删除!",
	            action: deleteCarTypeCompany
	          });
	          confirm.show();
	    });
	});
	//添加
    $("#close_modal_company").click(function(){
		$('#dialog_carTypeCompany_create').modal("hide");
	});
	$(document).on("click",".startService",function(){
		$('#dialog_carTypeCompany_create').modal();
	});
    $(document).on("click","#startService_company",function(){
		if($('#companyId_company').val().trim()==null  || $('#companyId_company').val().trim()==""){
			$.scojs_message("请选择开通公司！", $.scojs_message.TYPE_ERROR);
			return false;
		}
		if($('#tangzuAreaId_company').val().trim()==null  || $('#tangzuAreaId_company').val().trim()==""){
			$.scojs_message("请选择立即用车收费标准！", $.scojs_message.TYPE_ERROR);
			return false;
		}
		if($('#rizuAreaId_company').val().trim()==null  || $('#rizuAreaId_company').val().trim()==""){
			$.scojs_message("请选择日租收费标准！", $.scojs_message.TYPE_ERROR);
			return false;
		}
		if($('#banrizuAreaId_company').val().trim()==null  || $('#banrizuAreaId_company').val().trim()==""){
			$.scojs_message("请选择半日租收费标准！", $.scojs_message.TYPE_ERROR);
			return false;
		}
		if($('#jiejiAreaId_company').val().trim()==null  || $('#jiejiAreaId_company').val().trim()==""){
			$.scojs_message("请选择接机收费标准！", $.scojs_message.TYPE_ERROR);
			return false;
		}
		if($('#songjiAreaId_company').val().trim()==null  || $('#songjiAreaId_company').val().trim()==""){
			$.scojs_message("请选择送机收费标准！", $.scojs_message.TYPE_ERROR);
			return false;
		}
		if($('#jiezhanAreaId_company').val().trim()==null  || $('#jiezhanAreaId_company').val().trim()==""){
			$.scojs_message("请选择接站收费标准！", $.scojs_message.TYPE_ERROR);
			return false;
		}
		if($('#songzhanAreaId_company').val().trim()==null  || $('#songzhanAreaId_company').val().trim()==""){
			$.scojs_message("请选择送站收费标准！", $.scojs_message.TYPE_ERROR);
			return false;
		}
		$.post('${ctx}/zhuanche/startCarTypeCompany',
			{'carTypeId':${carTypeId},'companyId':$('#companyId_company').val(),
			'tangzuAreaId':$('#tangzuAreaId_company').val(),'rizuAreaId':$('#rizuAreaId_company').val(),'banrizuAreaId':$('#banrizuAreaId_company').val(),
			'jiejiAreaId':$('#jiejiAreaId_company').val(),'songjiAreaId':$('#songjiAreaId_company').val(),'jiezhanAreaId':$('#jiezhanAreaId_company').val(),
			'jiezhanAreaId':$('#jiezhanAreaId_company').val(),'songzhanAreaId':$('#songzhanAreaId_company').val(),
			'companyName':$('#companyId_company').find("option:selected").text(),
			'tangzuAreaName':$('#tangzuAreaId_company').find("option:selected").text(),
			'rizuAreaName':$('#rizuAreaId_company').find("option:selected").text(),
			'banrizuAreaName':$('#banrizuAreaId_company').find("option:selected").text(),
			'jiejiAreaName':$('#jiejiAreaId_company').find("option:selected").text(),
			'songjiAreaName':$('#songjiAreaId_company').find("option:selected").text(),
			'jiezhanAreaName':$('#jiezhanAreaId_company').find("option:selected").text(),
			'songzhanAreaName':$('#songzhanAreaId_company').find("option:selected").text()},
			function(data){
	           if(data.success){
	                $.scojs_message(data.message, $.scojs_message.TYPE_OK);
	                setTimeout(function(){
						window.location.reload(true);
					}, 1000);
		       }else{
	                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
		       }
		    },'json');
    });
    //修改
    $("#close_modal_company_update").click(function(){
		$('#dialog_carTypeCompany_update').modal("hide");
	});
	$(document).on("click",".updateCarType_company",function(){
		$("#companyId_update").val($(this).attr('companyId'));
		var companyName=$(this).attr('companyName');
		$("#companyName_update").html(companyName);
		var tangzuAreaId=$(this).attr('tangzuAreaId');
		var rizuAreaId=$(this).attr('rizuAreaId');
		var banrizuAreaId=$(this).attr('banrizuAreaId');
		var jiejiAreaId=$(this).attr('jiejiAreaId');
		var songjiAreaId=$(this).attr('songjiAreaId');
		var jiezhanAreaId=$(this).attr('jiezhanAreaId');
		var songzhanAreaId=$(this).attr('songzhanAreaId');
		
		$("#tangzuAreaId_company_update option").each(function(index,element){
		  	if($(element).attr("value")==tangzuAreaId){
		 		$(element).attr("selected","selected");
		 		return false;
		 	}
		});
		$("#rizuAreaId_company_update option").each(function(index,element){
		  	if($(element).attr("value")==rizuAreaId){
		 		$(element).attr("selected","selected");
		 		return false;
		 	}
		});
		$("#banrizuAreaId_company_update option").each(function(index,element){
		  	if($(element).attr("value")==banrizuAreaId){
		 		$(element).attr("selected","selected");
		 		return false;
		 	}
		});
		$("#jiejiAreaId_company_update option").each(function(index,element){
		  	if($(element).attr("value")==jiejiAreaId){
		 		$(element).attr("selected","selected");
		 		return false;
		 	}
		});
		$("#songjiAreaId_company_update option").each(function(index,element){
		  	if($(element).attr("value")==songjiAreaId){
		 		$(element).attr("selected","selected");
		 		return false;
		 	}
		});
		$("#jiezhanAreaId_company_update option").each(function(index,element){
		  	if($(element).attr("value")==jiezhanAreaId){
		 		$(element).attr("selected","selected");
		 		return false;
		 	}
		});
		$("#songzhanAreaId_company_update option").each(function(index,element){
		  	if($(element).attr("value")==songzhanAreaId){
		 		$(element).attr("selected","selected");
		 		return false;
		 	}
		});
		
    	$('#dialog_carTypeCompany_update').modal();
	});
    $(document).on("click","#startService_company_update",function(){
    	if($('#tangzuAreaId_company_update').val().trim()==null  || $('#tangzuAreaId_company_update').val().trim()==""){
			$.scojs_message("请选择立即用车收费标准！", $.scojs_message.TYPE_ERROR);
			return false;
		}
		if($('#rizuAreaId_company_update').val().trim()==null  || $('#rizuAreaId_company_update').val().trim()==""){
			$.scojs_message("请选择日租收费标准！", $.scojs_message.TYPE_ERROR);
			return false;
		}
		if($('#banrizuAreaId_company_update').val().trim()==null  || $('#banrizuAreaId_company_update').val().trim()==""){
			$.scojs_message("请选择半日租收费标准！", $.scojs_message.TYPE_ERROR);
			return false;
		}
		if($('#jiejiAreaId_company_update').val().trim()==null  || $('#jiejiAreaId_company_update').val().trim()==""){
			$.scojs_message("请选择接机收费标准！", $.scojs_message.TYPE_ERROR);
			return false;
		}
		if($('#songjiAreaId_company_update').val().trim()==null  || $('#songjiAreaId_company_update').val().trim()==""){
			$.scojs_message("请选择送机收费标准！", $.scojs_message.TYPE_ERROR);
			return false;
		}
		if($('#jiezhanAreaId_company_update').val().trim()==null  || $('#jiezhanAreaId_company_update').val().trim()==""){
			$.scojs_message("请选择接站收费标准！", $.scojs_message.TYPE_ERROR);
			return false;
		}
		if($('#songzhanAreaId_company_update').val().trim()==null  || $('#songzhanAreaId_company_update').val().trim()==""){
			$.scojs_message("请选择送站收费标准！", $.scojs_message.TYPE_ERROR);
			return false;
		}
		$.post('${ctx}/zhuanche/updateCarTypeCompany',
			{'carTypeId':${carTypeId},'companyId':$('#companyId_update').val(),'companyName':$("#companyName_update").html(),
			'tangzuAreaId':$('#tangzuAreaId_company_update').val(),'rizuAreaId':$('#rizuAreaId_company_update').val(),'banrizuAreaId':$('#banrizuAreaId_company_update').val(),
			'jiejiAreaId':$('#jiejiAreaId_company_update').val(),'songjiAreaId':$('#songjiAreaId_company_update').val(),'jiezhanAreaId':$('#jiezhanAreaId_company_update').val(),
			'jiezhanAreaId':$('#jiezhanAreaId_company_update').val(),'songzhanAreaId':$('#songzhanAreaId_company_update').val(),
			'tangzuAreaName':$('#tangzuAreaId_company_update').find("option:selected").text(),
			'rizuAreaName':$('#rizuAreaId_company_update').find("option:selected").text(),
			'banrizuAreaName':$('#banrizuAreaId_company_update').find("option:selected").text(),
			'jiejiAreaName':$('#jiejiAreaId_company_update').find("option:selected").text(),
			'songjiAreaName':$('#songjiAreaId_company_update').find("option:selected").text(),
			'jiezhanAreaName':$('#jiezhanAreaId_company_update').find("option:selected").text(),
			'songzhanAreaName':$('#songzhanAreaId_company_update').find("option:selected").text()},
			function(data){
	           if(data.success){
	                $.scojs_message(data.message, $.scojs_message.TYPE_OK);
	                setTimeout(function(){
						window.location.reload(true);
					}, 1000);
		       }else{
	                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
	                setTimeout(function(){
						window.location.reload(true);
					}, 1000);
		       }
		    },'json');
		
    });
   
</script>
</@override>
<@extends name="../layout.ftl"/>
